clear
 
clear matrix
set memory 1000m
set more off
cap log close

cd "/Users/..."

global do_file="‎⁨/Users/.../do_file"
global log_file="/Users/.../log_file"
global raw_data="/Users/.../raw_data⁩⁩"
global working_data="/Users/.../working_data"
global results="/Users/.../results"




*forvalues i=1(1)249{
*forvalues i=252(1)347{

forvalues i=350(1)363{
use working_data/city_names.dta, clear

local city_name=city_url[`i']
display "`city_name'"
display "`i'"

import delimited "/Users/.../weather_info/weather-csv/`city_name'.csv", encoding(utf8) clear
gen city_urls="`city_name'"

drop if _n==1

gen date=date(v1, "YMD")
format date %td

*tab v2
gen temp=strpos(v2, "/")
gen temp_length=length(v2)

gen weather_1=substr(v2, 1, temp-1)
gen weather_2=substr(v2, temp+1, temp_length-temp)

drop temp temp_length

gen temp=strpos(v3, "℃")
gen high_temper=substr(v3, 1, temp-1)
destring high_temper, replace force

gen temp_length=length(v3)
gen temp_v3=substr(v3,temp+4, temp_length-(temp+4)+1)

drop temp
gen temp=strpos(temp_v3, "℃")
gen low_temper=substr(temp_v3, 1, temp-1)
destring low_temper, replace force


drop temp
gen temp=strpos(v4, "/")
drop temp_length
gen temp_length=length(v4)

gen wind1=substr(v4, 1, temp-1)
gen wind2=substr(v4, temp+1, temp_length-temp)

keep date weather_1 weather_2 high_temper low_temper wind1 wind2 city_urls
save "/Users/.../weather_info/weather-dta/`i'.dta", replace

}

use "/Users/.../weather_info/weather-dta/1.dta", clear

forvalues i=2(1)249{
append using "/Users/.../weather_info/weather-dta/`i'.dta"
}

forvalues i=252(1)347{
append using "/Users/.../weather_info/weather-dta/`i'.dta"
}

forvalues i=350(1)363{
append using "/Users/.../weather_info/weather-dta/`i'.dta"
}


sort city_urls date
bysort city_urls date: gen temp=_n

tab temp
list city_urls date if temp==2

drop if temp==2
drop temp

save working_data/weather_all.dta, replace


